home *** CD-ROM | disk | FTP | other *** search
-
-
- /*
- This MacHack implements styled text in Metrowerk's (and BBEdit's) Editing Windows.
- by Matthew Xavier Mora mxmora@apple.com
-
- Because of the fact that both Metrowerks and BBedit draw and measure text differently
- this is only a visible hack. You don't really want to use this for real work since
- hit testing is off for lines of text that have been modified. Also this is a 68k
- patch on what is most likely a native trap.
-
- (6-27-97)
- */
-
- #ifndef THINK_C
- # ifndef __MWERKS__
- # error unknown compiler
- # endif
- #endif
-
- //#define OLDROUTINENAMES 0
- #define SystemSevenFiveOrLater 1
-
- #define kMyID (128)
-
- //#include <strings.h>
- //#include <Resources.h>
- #include <Memory.h>
- #include <Events.h>
- #include <SetUpA4.h>
- #include <Processes.h>
- #include <ToolUtils.h>
- #include <Traps.h>
- //#include <Notification.h>
- #include <Windows.h>
- #include <Gestalt.h>
- #include <LowMem.h>
-
- #include "ShowInitIcon.h"
- #include "StyledEdit.h"
-
- QDTextUPP oldStdText;
- QDTxMeasUPP oldTextMeasure;
-
- MyGlobalsPtr globs;
- short err;
-
- pascal void NewStdText(short count,char *textAddr,Point numer,Point denom);
- pascal short NewTextMeasure(short count, Ptr textAddr, Point *numer, Point *denom, FontInfo *info);
-
- //-----------------------------------------------------------------------------------------------
- pascal void NewStdText(short count,char *textAddr,Point numer,Point denom)
- //-----------------------------------------------------------------------------------------------
- {
- long oldA4 = SetUpA4();
- Ptr oldAddr = textAddr;
- short oldFace;
- CGrafPtr theWindow ;
- RGBColor theColor;
- Boolean alreadyCalled;
-
- alreadyCalled = false;
-
- if (globs->enabled) {
- //offset = contains(textAddr, srcLen, findStr, 0);
- //theWindow = (CGrafPtr)FrontWindow();
- GetPort(&(GrafPtr)theWindow);
- if (theWindow) {
-
- GetForeColor(&theColor);
- if (theColor.red == 0 && theColor.green == 0 && theColor.blue ) { // if kinda blue
-
- // set the face
- oldFace = theWindow->txFace;
- TextFace(bold + condense);
- CallQDTextProc(oldStdText, count, textAddr, numer, denom);
- TextFace(oldFace);
- alreadyCalled = true;
- }
- }
- }
- if (!alreadyCalled) {
- CallQDTextProc(oldStdText, count, textAddr, numer, denom);
- }
-
- RestoreA4(oldA4);
- }
-
- //-----------------------------------------------------------------------------------------------
- pascal short NewTextMeasure(short count, Ptr textAddr, Point *numer, Point *denom, FontInfo *info)
- //-----------------------------------------------------------------------------------------------
- {
- long oldA4 = SetUpA4();
- short result;
- short oldFace;
- CGrafPtr theWindow ;
- RGBColor theColor;
- Boolean alreadyCalled;
-
- alreadyCalled =false;
- if (globs->enabled) {
- GetPort(&(GrafPtr)theWindow);
- if (theWindow) {
- GetForeColor(&theColor);
- if (theColor.red == 0 && theColor.green == 0 && theColor.blue ) { // if it is sorta blue
- // set the face to bold condense
- oldFace = theWindow->txFace;
- TextFace(bold + condense);
- result = CallQDTxMeasProc(oldTextMeasure,count,textAddr,numer,denom,info);
- TextFace(oldFace);
- alreadyCalled = true;
- } else if (theColor.red && theColor.green == 0 && theColor.blue ==0 ) {
- // set the face to italic
- oldFace = theWindow->txFace;
- TextFace(italic);
- result = CallQDTxMeasProc(oldTextMeasure,count,textAddr,numer,denom,info);
- TextFace(oldFace);
- alreadyCalled = true;
- }
- }
- }
-
- if (!alreadyCalled) {
- result = CallQDTxMeasProc(oldTextMeasure,count,textAddr,numer,denom,info);
- }
-
- RestoreA4(oldA4);
- return result;
- }
-
- #if defined (__MWERKS__)
- # include <A4Stuff.h>
- #elif defined (THINK_C)
- pascal void * GetA0 (void) = { 0x2E88 };
- #endif
-
- void main (void) {
- #if defined (__MWERKS__)
- void __Startup__ (void);
- long oldA4 = SetCurrentA4 ( );
- RememberA4 ( );
- DetachResource (RecoverHandle ((Ptr) __Startup__));
- #elif defined (THINK_C)
- void *me = GetA0 ( );
- RememberA0 ( );
- DetachResource (RecoverHandle (me));
- SetUpA4 ( );
- #endif
-
- globs = (MyGlobalsPtr)NewPtrSysClear(sizeof(MyGlobals));
-
- if (globs) {
- globs->enabled = true;
- }
-
- err = NewGestaltValue(kStyledEditSig,(long)globs);
-
- oldStdText = (QDTextUPP)GetToolboxTrapAddress(_StdText);
- SetToolboxTrapAddress((UniversalProcPtr)NewQDTextProc(NewStdText),_StdText);
-
- oldTextMeasure = (QDTxMeasUPP)GetToolboxTrapAddress(_StdTxMeas);
- SetToolboxTrapAddress((UniversalProcPtr)NewQDTxMeasProc(NewTextMeasure),_StdTxMeas);
-
- ShowInitIcon (kMyID, true);
-
- #if defined (__MWERKS__)
- SetA4 (oldA4);
- #elif defined (THINK_C)
- RestoreA4 ( );
- #endif
- }
-
-
-
-